

jQuery(function ($) {
    var user_info = JSON.parse(localStorage.getItem('user_info'));
    if (!user_info) {
        window.location.href = "/login/login.html";
    }
    var id = user_info.id;
   
    //余额查询切换
    $('.balance_query li').click(function () {
        var index = $(this).index();
        $(this).addClass("add_color").siblings().removeClass("add_color");
        $(".balance_explain").eq(index).addClass('open').siblings().removeClass("open");
    });
    //余额明细
    balanceRecord();
    function balanceRecord() {
        var html = "";
        var param = {
            "[]": {
                "UserBanlanceBill": {
                    "user_id": id
                }
            }
        };
        send_ajax('post', '/get', param, function (data) {
            if (data.code == 200) {
                var user_info = JSON.parse(localStorage.getItem('user_info'));
                var balance = user_info.balance;
                if (balance.toString().indexOf(".") != -1) {
                    var integer = balance.toString().split('.')[0];
                    var decimal = balance.toString().split('.')[1];
                    $('.big_num').html(integer);
                    $('.decimal').html(decimal);
                } else {
                    $('.big_num').html(balance);
                }
                if (data["[]"] != undefined) {
                    var data = data["[]"];                   
                    for (var i = 0; i < data.length; i++) {
                        html += '\n                        <li class="item">\n                            <span>' + data[i].UserBanlanceBill.create_time.split(".")[0] + '</span>\n                            <span>' + data[i].UserBanlanceBill.balance + '</span>\n                            <span>' + (data[i].UserBanlanceBill.note ? data[i].UserBanlanceBill.note : "") + '</span>\n                        </li>\n                    ';
                    }
                    $('.balanceRecord').html(html);
                }
            }
        });
    }
    //畜牧币明细
    // ycbalance()
    function ycbalance() {
        var html = "";
        var param = {
            "[]": {
                "UserPointBill": {
                    "user_id": id
                }
            }
        };
        send_ajax('post', '/get', param, function (data) {

            if (data.code == 200 && data["[]"] != undefined) {
                var data = data["[]"];

                for (var i = 0; i < data.length; i++) {
                    html += '\n                        <li class="item">\n                            <span>' + data[i].UserBanlanceBill.create_time.split(".")[0] + '</span>\n                            <span>' + data[i].UserBanlanceBill.balance + '</span>\n                            <span>' + (data[i].UserBanlanceBill.note ? data[i].UserBanlanceBill.note : "") + '</span>\n                        </li>\n                    ';
                }
            }
        });
    }
});